package com.woniu.darryringmall.front.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.darryringmall.front.entity.Cart;
import com.woniu.darryringmall.front.entity.CartVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 购物车mapper
 */
public interface CartMapper extends BaseMapper<Cart> {

    @Select("select c.id,c.nums,g.id gid,g.image,c.selected,g.name,gs.price,gs.specvalues from mall_goods g,mall_goods_spec gs,mall_cart c where c.goodsId=g.id and g.id=gs.goodsId and c.goodsSpecId=gs.id and c.userId=#{userId}")
    List<CartVo> carts(int userId);

    @Insert("insert into mall_cart(userId,nums,selected,goodsId,goodsSpecId) values(#{userId},#{nums},#{selected},#{goodsId},#{goodsSpecId})")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    void add(Cart cart);

}
